import sdk from 'sdk'
import { getPayConfig } from 'api'
import { getFullUrl } from 'utils/helper/query'

export default {
  methods: {
    async $pay_payOrderSDK (param) {
      // TODO 支付结果页
      let callbackUrl = getFullUrl('/pages/booking-result/index') + '?orderNo=' + param.merchantOrderNo
      // vm.$loading({
      //   mask: true,
      //   closeOnClickMask: false
      // })
      let { amount, merchantOrderNo, hotelName } = param
      getPayConfig({ amount, merchantOrderNo, returnUrl: callbackUrl }).then(res => {
        console.log('getPayConfig')
        console.log('res.data')
        // vm.$loading.close()
        let config = res.data
        let sdkParam = {
          merchantNo: config.merchantNo,
          merchantOrderNo: config.merchantOrderNo,
          biometricsSignData: config.merchantOrderNo,
          token: config.token,
          mebid: config.mebid,
          subject: hotelName || '海外酒店支付',
          paymentDes1: '订单编号:' + param.merchantOrderNo,
          totalAmount: config.totalFee,
          callbackUrl: callbackUrl,
          notifyUrl: config.notifyUrl
        }
    
        if (param.payCancelUrl) {
          sdkParam.payCancelUrl = param.payCancelUrl
        }
    
        sdk.payOrderSDK(sdkParam)
      }).catch(err => {
        // vm.$toast({
        //   content: err.resultMsg
        // })
        // vm.$loading.close()
      })
    }
  }
}